﻿#pragma once

#include <vtkm/rendering/CanvasRayTracer.h>
#include <vtkm/rendering/MapperQuad.h>
#include <vtkm/rendering/MapperPoint.h>
#include <vtkm/rendering/MapperWireframer.h>
#include <vtkm/rendering/MapperRayTracer.h>
#include <vtkm/rendering/Scene.h>
#include <vtkm/rendering/View2D.h>

class EulerSystem;
class ImgOutput
{
public:
  ImgOutput(const EulerSystem& sys)
    : _sys(sys)
  {
  }
  ~ImgOutput(){};

  void Execute()
  {
    const auto& sln = _sys.Solution();
    const auto& mesh = _sys.GetMesh();
    vtkm::cont::DataSet dataSet;
    dataSet.AddCoordinateSystem(mesh.GetCoordinate());
    dataSet.SetCellSet(mesh.GetCellSet());
    for (UInt8 eq = 0; eq < 5; eq++)
    {
      dataSet.AddCellField("variable" + std::to_string(eq), ArrayHandle<FloatDefault>{});
    }
    for (UInt8 eq = 0; eq < EulerSystem::NUM_VARIABLES; eq++)
    {
      Invoker{}(EulerSystem::WriteVariable{ eq }, sln, dataSet.GetField(eq));
    }



    vtkm::rendering::Scene scene;
    vtkm::rendering::Actor actor(dataSet.GetCellSet(),
                                 dataSet.GetCoordinateSystem(),
                                 dataSet.GetCellField("variable0"),
                                 vtkm::cont::ColorTable("Rainbow Uniform"));
    scene.AddActor(actor);
    vtkm::rendering::CanvasRayTracer canvas(600, 600);
    vtkm ::rendering::MapperRayTracer mapper;
    mapper.SetShadingOn(false);
    vtkm::rendering::View2D view(scene, mapper, canvas);
    view.Paint();
    view.SaveAs("out.png");
  }

private:
  const EulerSystem& _sys;
};
